﻿using System;
using System.Collections.Generic;

using System.Web;
using Yu.Cms.Common;
using System.Web.UI.WebControls;

namespace Yu.Cms.Web
{
    public class BaseCtrl : System.Web.UI.UserControl
    {
        /// <summary>
        /// 读取配置
        /// </summary>
        protected Yu.Cms.Config.SiteConfigInfo siteModel = Yu.Cms.Config.SiteConfig.GetConfig();

         

        #region "实例化BLL"

        protected Yu.Cms.BLL.Admin bllAdmin = new Yu.Cms.BLL.Admin();

        protected Yu.Cms.BLL.album bllalbum = new Yu.Cms.BLL.album();

        protected Yu.Cms.BLL.albumType bllalbumType = new Yu.Cms.BLL.albumType();

        protected Yu.Cms.BLL.Annonce bllAnnonce = new Yu.Cms.BLL.Annonce();

        protected Yu.Cms.BLL.BigType bllBigType = new Yu.Cms.BLL.BigType();

        protected Yu.Cms.BLL.Book bllBook = new Yu.Cms.BLL.Book();

        protected Yu.Cms.BLL.Comment bllComment = new Yu.Cms.BLL.Comment();

        protected Yu.Cms.BLL.Content bllContent = new Yu.Cms.BLL.Content();

        protected Yu.Cms.BLL.SmallType bllSmallType = new Yu.Cms.BLL.SmallType();

        protected Yu.Cms.BLL.Tags bllTags = new Yu.Cms.BLL.Tags();
        #endregion

        /// <summary>
        /// 根据ID获取大类实体
        /// </summary>
        /// <param name="BigTypeID"></param>
        /// <returns></returns>
        protected string GetBigTypeNameByID(object BigTypeID)
        {
            int intBigType = Utils.StrToInt(BigTypeID.ToString(), 0);
            return bllBigType.GetModel(intBigType).BigTypeName;
        }

        /// <summary>
        /// 根据ID获取小类实体
        /// </summary>
        /// <param name="SmallTypeID"></param>
        /// <returns></returns>
        protected string GetSmallTypeNameByID(object SmallTypeID)
        {
            int intSmallType = Utils.StrToInt(SmallTypeID.ToString(), 0);
            return bllSmallType.GetModel(intSmallType).SmallTypeName;
        }

        /// <summary>
        /// 是否置顶
        /// </summary>
        /// <param name="AllowTop"></param>
        /// <returns></returns>
        protected string GetTopName(object AllowTop)
        {
            bool bAllow = Utils.StrToBool(AllowTop.ToString(), false);
            return bAllow ? "<span>[顶]</span>" : "";
        }

        /// <summary>
        /// 是否允许评论
        /// </summary>
        /// <param name="AllowComment"></param>
        /// <returns></returns>
        protected string GetCommentName(object AllowComment)
        {
            bool bComment = Utils.StrToBool(AllowComment.ToString(), false);
            return bComment ? "<span>[评]</span>" : "";
        }

        /// <summary>
        /// 是否发布
        /// </summary>
        /// <param name="AllowShow"></param>
        /// <returns></returns>
        protected string GetAllowShow(object AllowShow)
        {
            bool bAllowShow = Utils.StrToBool(AllowShow.ToString(), false);
            return bAllowShow ? "" : "<span>[未发表]</span>";
        }

        /// <summary>
        /// 评论是否审核通过
        /// </summary>
        /// <param name="isPub"></param>
        /// <returns></returns>
        protected string GetIsPub(object isPub)
        {
            bool bIsPub = Utils.StrToBool(isPub.ToString(), false);
            return bIsPub ? "" : "<span>[未审核]</span>";
        }


        /// <summary>
        /// 是否热门
        /// </summary>
        /// <param name="isHot"></param>
        /// <returns></returns>
        protected string GetIsHot(object isHot)
        {
            bool bIsHot = Utils.StrToBool(isHot.ToString(), false);
            return bIsHot ? "<i class=\"hot\">热门</i>" : "";
        }

        /// <summary>
        /// 是否推荐（置顶）
        /// </summary>
        /// <param name="isHot"></param>
        /// <returns></returns>
        protected string GetIsTop(object isTop)
        {
            bool bIsTop = Utils.StrToBool(isTop.ToString(), false);
            return bIsTop ? "<i class=\"top\">推荐</i>" : "";
        }


        /// <summary>
        /// 是否是最新 //7天之内为最新文章
        /// </summary>
        /// <param name="isNew"></param>
        /// <returns></returns>
        protected string GetIsNew(object isNew)
        {
            if (Utils.DateDiff(Convert.ToDateTime(isNew)) < 7)
            {
                return "<i class=\"new\">最新</i>";
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 返回时间格式 MM-dd mm:ss
        /// </summary>
        /// <param name="fDate"></param>
        /// <returns></returns>
        protected string GetDateAndTime(object fDate)
        {
            if (fDate!=null)
            {
                return Utils.GetDateAndTime(fDate.ToString());
            }
            else
            {
                return null;
            }
        }

        protected string GetYDateAndTime(object fDate)
        {
            if (fDate != null)
            {
                return Utils.GetYearDateTime(fDate.ToString());
            }
            else
            {
                return null;
            }
        }

        #region "评论"
        protected string OutCommentTitle(object url, object title)
        {
            string strUrl = Utils.ToStr(url);
            if (string.IsNullOrEmpty(strUrl))
            {
                return Utils.ToStr(title);
            }
            else
            {
               
                return "<a class=\"url\" rel=\"external nofollow\" title=\"访问"+ title +"的网站\" href=\"" + Utils.StartWith(strUrl) + "\" target=\"_blank\" title=\"\">" + Utils.ToStr(title) + "</a>";
            }
        }

        /// <summary>
        /// 返回评论类型ReturnUrl
        /// </summary>
        /// <param name="TypeID"></param>
        /// <returns></returns>
        protected string OutCommentType(object TypeID)
        {
            int cType = Utils.StrToInt(TypeID, 0);
            if (cType == (int)Yu.Enum.CTypeID.Artice)
            {
                return "/Article.aspx?PostID=";
            }
            else if (cType == (int)Yu.Enum.CTypeID.Pic)
            {
                return "/AlbumList.aspx?PostID=";
            }
            else
            {
                return "";
            }
        }

        #endregion

        #region 

      
        #endregion
    }
}
